package com.itheima.wemedia.controller;

import com.itheima.admin.pojo.AdChannel;
import com.itheima.common.vo.ResultVo;
import com.itheima.wemedia.pojo.WmUser;
import com.itheima.wemedia.service.ApiService;
import com.itheima.wemedia.service.WmMaterialService;
import com.itheima.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import com.itheima.wemedia.pojo.WmMaterial;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @version 1.0
 * @description 说明
 * @package com.itheima.wemedia.controller
 */
@RestController
public class ApiController {

    @Autowired
    private WmUserService wmUserService;

    @Autowired
    private WmMaterialService wmMaterialService;

    @Autowired
    private ApiService apiService;

    /**
     * 远程调用添加自媒体账号
     * @param wmUser
     * @return
     */
    @PostMapping("/api/wmUser/add")
    public ResultVo<WmUser> add(@RequestBody WmUser wmUser) {
        wmUserService.save(wmUser);
        return ResultVo.ok(wmUser);
    }

    /**
     * 通appUserId查询自媒体账号信息
     * @param appUserId
     * @return
     */
    @GetMapping("/api/wmUser/{appUserId}")
    public ResultVo<WmUser> getByAppUserId(@PathVariable(name = "appUserId") Integer appUserId){
        WmUser wmUser = wmUserService.getByAppUserId(appUserId);
        return ResultVo.ok(wmUser);
    }

    /**
     * 添加素材
     * @param wmMaterial
     * @return
     */
    @PostMapping("/api/wmMaterial/add")
    public ResultVo add(@RequestBody WmMaterial wmMaterial){
        wmMaterialService.save(wmMaterial);
        return ResultVo.ok();
    }

    /**
     * 查询频道列表
     * @return
     */
    @GetMapping("/channel/channels")
    public ResultVo<List<AdChannel>> getChannelList(){
        List<AdChannel> list = apiService.getChannelList();
        return ResultVo.ok(list);
    }

}
